
/*
'===============================================================================
'  MP.LayerHelper.MP_OBS.BL.AspnetRolesManager
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MP.LayerHelper.MP_OBS.BLL;
using MP.LayerHelper.MP_OBS.DAL;
using MP.LayerHelper.MP_OBS.DAL.EntityClasses;
using MP.LayerHelper.MP_OBS.DAL.FactoryClasses;
using MP.LayerHelper.MP_OBS.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MP.LayerHelper.MP_OBS.BLL
{
	public class AspnetRolesManager : AspnetRolesManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public AspnetRolesManager()
		{
			// Nothing for now.
		}
		
		/// <summary>
		/// Method to create an instance of AspnetRolesManager
		/// </summary>
		/// <returns>An instant of AspnetRolesManager class</returns>
		public static AspnetRolesManager CreateInstant()
		{
			return new AspnetRolesManager();
		}

        public AspnetRolesEntity GetRole(string rolename, string applicationname)
        {
            EntityCollection<AspnetRolesEntity> items = new EntityCollection<AspnetRolesEntity>();

            IPredicateExpression predicate = new PredicateExpression();
            predicate.Add(AspnetRolesFields.RoleName == rolename);
            predicate.Add(AspnetRolesFields.ApplicationId == AspnetApplicationsManager.CreateInstant().GetApplicationId(applicationname));

            RelationPredicateBucket filter = new RelationPredicateBucket();
            filter.PredicateExpression.Add(predicate);
            using (DataAccessAdapterBase adapter = new DataAccessAdapterFactory().CreateAdapter())
            {
                adapter.FetchEntityCollection(items, filter);
            }
            if (items != null && items.Count > 0)
                return items[0];
            return null;
        }
	}
}
